package cn.leshua.util;

import java.text.SimpleDateFormat;

public class ReqSerialNoUtil {

	private static ThreadLocal<SimpleDateFormat> sdf = new ThreadLocal<SimpleDateFormat>() {
		@Override
		protected SimpleDateFormat initialValue() {
			return new SimpleDateFormat("yyyyMMddHHmmssSSS");
		}
	};

	private static volatile int reqSerialNo = 10000;

	public static String getReqSerialNo() {
		return getReqSerialNo(System.currentTimeMillis());
	}

	public static String getReqSerialNo(long timeMillis) {
		reqSerialNo++;
		if (reqSerialNo > 99999) {
			reqSerialNo = 10000;
		}
		return sdf.get().format(timeMillis) + reqSerialNo;
	}


	public static void main(String[] args) {
		System.out.println(ReqSerialNoUtil.getReqSerialNo());
	}

}
